package Euler3;

public class PrimeFactor {
	public static void main(String[] args) {
		long num = 600851475143L;
		long current = num;
		long divisor = 2;
		
		//Since num is too large to be an int, we must minimze it to less than 2^31.
		while(current > 0)//Math.pow(2, 31))
		{
			current = num/divisor;
			
			if((current*divisor) == num)
			{
				if(isPrime(current)){
					System.out.println(current);
					break;
				}
			}
			
			divisor++;
		}
	}
	
	//Check if a number is prime.
	public static boolean isPrime(long num)
	{
		if(num < 1)
		{
			return false;
		}
		else if(num == 1) 
		{
			return true;
		}
		
		for(long i = 2; i <= (num/2); i++)
		{
			if(num % i == 0)
			{
				return false;
			}
		}
		
		return true;
	}
}
